<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" label="团队架构设置" name="团队架构设置">
          <el-row>
            <el-col :span="24">
              <el-form-item label="成为团长:">
                <el-radio-group v-model="form.topagent">
                  <el-radio label="1">直推</el-radio>
                  <el-radio label="2">直推+间推</el-radio>
                </el-radio-group>
                <div class="help-block">脱离上级成为顶层分销商</div>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="推荐数量:">
                <el-input
                  v-model="form.recommend_quantity"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  placeholder="请输入推荐数量"
                >
                  <template slot="append">人</template>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="下级团队去留:">
                <el-radio-group v-model="form.team_goorremain">
                  <el-radio label="1">留给上级</el-radio>
                  <el-radio label="2">带走</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="平级奖比例:">
                <el-input
                  v-model="form.cash_max_day"
                  style="width:300px;"
                  auto-complete="off"
                  clearable
                  placeholder="请输入平级奖比例"
                >
                  <template slot="append">%</template>
                </el-input>
                <div class="help-block">0元表示不设平级奖</div>
              </el-form-item>
            </el-col>
          </el-row>

        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: 'Configagentteam',
  components: {
  },
  data() {
    return {
      form: {
      },
      loading: false,
      activeName: '团队架构设置',
      rules: {}
    }
  },
  mounted() {
    this.$api.post('/config/getInfo', {
      mo: 'agentteam'
    }).then(res => {
      this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
      this.setDefaultVal('keyword')
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$api.post('/config/update', this.form).then(res => {
            if (res.code == 2000) {
              this.$message({ message: '操作成功', type: 'success' })
            } else {
              this.$message({ message: res.msg, type: 'info' })
            }
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    setDefaultVal(key) {
      if (this.form[key] == null || this.form[key] == '') {
        this.form[key] = []
      }
    },
    addItem() {
      const that = this
      that.form.cash_service_charge_list.push({
        days: '',
        calculate_method: '0',
        price: ''
      })
    },
    deleteItem(i) {
      if (this.form.cash_service_charge_list.length <= 1) {
        return false
      }
      this.form.cash_service_charge_list.splice(i, 1)
    }
  }
}
</script>
